package cn.edu.cug.cs.gtl.renders.openinventor.projectors;

import cn.edu.cug.cs.gtl.apis.render.basics.Plane;
import cn.edu.cug.cs.gtl.apis.render.basics.Vec2f;
import cn.edu.cug.cs.gtl.apis.render.basics.Vec3f;
import cn.edu.cug.cs.gtl.apis.render.projectors.PlaneProjector;
import cn.edu.cug.cs.gtl.renders.openinventor.basics.PlaneImpl;
import cn.edu.cug.cs.gtl.renders.openinventor.basics.Vec3fImpl;
import com.openinventor.inventor.SbPlane;
import com.openinventor.inventor.SbVec2f;
import com.openinventor.inventor.SbVec3f;
import com.openinventor.inventor.projectors.SbPlaneProjector;

public class PlaneProjectorImpl extends ProjectorImpl implements PlaneProjector {
    public PlaneProjectorImpl(SbPlaneProjector p) {
        super(p);
    }

    /**
     * Gets the plane to use.
     *
     * @return
     */
    @Override
    public Plane getPlane() {
        return new PlaneImpl(((SbPlaneProjector)nativeObject).getPlane());
    }

    /**
     * Gets a vector given the current mouse point.
     *
     * @param mousePosition
     * @return
     */
    @Override
    public Vec3f getVector(Vec2f mousePosition) {
        return new Vec3fImpl(((SbPlaneProjector)nativeObject).getVector((SbVec2f) mousePosition.getNativeObject()));
    }

    /**
     * Gets a vector on this plane given two normalized mouse positions.
     *
     * @param mousePosition1
     * @param mousePosition2
     * @return
     */
    @Override
    public Vec3f getVector(Vec2f mousePosition1, Vec2f mousePosition2) {
        return new Vec3fImpl(
                ((SbPlaneProjector)nativeObject).getVector(
                        (SbVec2f) mousePosition1.getNativeObject(),
                        (SbVec2f) mousePosition2.getNativeObject()
                )
        );
    }

    /**
     * Gets whether the projector should be oriented towards the eye.
     *
     * @return
     */
    @Override
    public boolean isOrientToEye() {
        return ((SbPlaneProjector)nativeObject).isOrientToEye();
    }

    /**
     * Sets whether the projector should be oriented towards the eye.
     *
     * @param orientToEye
     */
    @Override
    public void setOrientToEye(boolean orientToEye) {
        ((SbPlaneProjector)nativeObject).setOrientToEye(orientToEye);
    }

    /**
     * Sets the plane to use.
     *
     * @param plane
     */
    @Override
    public void setPlane(Plane plane) {
        ((SbPlaneProjector)nativeObject).setPlane((SbPlane) plane.getNativeObject());
    }

    /**
     * Sets the initial mouse position.
     *
     * @param mousePosition
     */
    @Override
    public void setStartPosition(Vec2f mousePosition) {
        ((SbPlaneProjector)nativeObject).setStartPosition((SbVec2f) mousePosition.getNativeObject());
    }

    /**
     * Sets the initial position from a point on the projector.
     *
     * @param point
     */
    @Override
    public void setStartPosition(Vec3f point) {
        ((SbPlaneProjector)nativeObject).setStartPosition((SbVec3f) point.getNativeObject());
    }
}
